package it.unisa.ingegneria.tdp.esercitazione5;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Classe che rappresenta il vertice di un grafo
 * 
 */

public class MyVertex<T> extends MyItem<T> implements Vertex<T> {

	private T key;
	private ArrayList<MyEdge<T>> out;
	private MyVertex<T> parent;


	public MyVertex<T> getParent() {
		return parent;
	}

	public void setParent(MyVertex<T> p) {
		this.parent = p;
	}

	public MyVertex(T key)
	{
		this.key=key;
		out=new ArrayList<MyEdge<T>>();

	}

	public ArrayList<MyVertex<T>> outgoingVertexes() {

		ArrayList<MyVertex<T>> ris=new ArrayList<MyVertex<T>>();
		Iterator<MyEdge<T>> i = this.out.iterator();
		MyEdge<T> temp;

		while(i.hasNext())
		{
			temp=i.next();
			ris.add(temp.getDrain());
		}

		return ris;
	}

	public ArrayList<MyEdge<T>> getOutgoigEdges() {
		return out;
	}


	public void setOutgoingEdges(ArrayList<MyEdge<T>> e) {
		this.out = e;
	}

	public Boolean addOutEdge(MyEdge<T> arco)
	{
		return this.out.add(arco);
	}

	public String toString()
	{
		return key.toString();
	}



}

